#include <stdio.h>
#include <stdlib.h>

long pows(int a, int b)
{
    int i;
    long re;

    re = 1;
    for (i = 0; i < b; i++) {
        re *= a;
    }

    return re;
}

int main (int argc, char const* argv[])
{
    int i, j, a, b, n, len, t;
    char buf[256];
    long sum;

    while (scanf("%d", &n) != EOF) {
        sum = 0;
        for (i = 0; i < n; i++) {
            scanf("%s", buf);
            j = 0; a = 0;
            while (buf[j] != '(') {
                a = a * 10 + buf[j] - '0';
                j++;
            }
            len = j;
            j++;
            b = 0;
            while (buf[j] != ')') {
                b = b * 10 + buf[j] - '0';
                j++;
            }

            t = 0;
            for (j = 0; j < len; j++) {
                t += (a % 10) * pows(b, j);
                a = a / 10;
            }
            
            sum += t;
        }
        printf("%ld\n", sum);
    }

    return 0;
}
